﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class user_UserLoginajax : NetCMS.Web.UI.BasePage
{
    protected const string newLine = "\r\n";
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";
        UserOp();
    }

    /// <summary>
    /// 取得操作类型
    /// </summary>
    protected void UserOp()
    {
        string str_Type = Request.QueryString["Type"];
        switch (str_Type)
        {
            case "getLoginForm":
                try
                {
                    CheckUserLogin();
                }
                catch
                {
                    Response.Clear();
                    UserLoginForm();
                }
                Response.Write(UserLoginTrue());
                Response.End();
                break;
            case "Login":
                UserLogin();
                break;
            case "LoginOut":
                UserLoginOut();
                break;
        }
    }

    /// <summary>
    /// 检测用户登录
    /// </summary>
    protected void UserLogin()
    {
        string str_UserNum = Request.QueryString["UserNum"];
        string str_UserPwd = Request.QueryString["UserPwd"];
        try
        {
            AjaxLogin(str_UserNum, str_UserPwd);
        }
        catch (Exception e)
        {
            Response.Write("ERR$$$" + e.Message);
            Response.End();
        }
        Response.Write("SUC$$$" + UserLoginTrue());

        #region 动易，动网，Oblog 整合
        NetCMS.API.PDO.PDOAction pdo = new NetCMS.API.PDO.PDOAction();
        if (pdo.Enabled())
        {
            pdo.Login(str_UserNum, str_UserPwd, 1);
        }
        #endregion

        Response.End();
    }

    /// <summary>
    /// 登录成功之后返回成功列表
    /// </summary>
    /// <returns></returns>
    protected string UserLoginTrue()
    {
        string str_LoginP = Request.QueryString["LoginP"];
        string str_UserLogin = "";
        if (str_LoginP == "true")
        {
            str_UserLogin += "   <div style=\"text-align:center;\">" + newLine;
            str_UserLogin += "       <table><tr><td align=\"center\">欢迎<span style=\"font-weight:bold;\"><font color=\"red\">" + NetCMS.Global.Current.UserName + "</font></span> 再次登录</td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/index.aspx?urls=" + NetCMS.Publish.CommonData.getUrl() + "/" + NetCMS.Config.UIConfig.dirUser + "/info/userinfo.aspx\" target=\"_blank\">资料</a></td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/index.aspx?urls=" + NetCMS.Publish.CommonData.getUrl() + "/" + NetCMS.Config.UIConfig.dirUser + "/photo/Photoalbumlist.aspx\" target=\"_blank\">相册</a></td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/Index.aspx\" target=\"_blank\">会员中心</a></td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"javascript:LoginOut();\">退出</a></td></tr> ";
            str_UserLogin += "   </div>" + newLine;
        }
        else
        {
            str_UserLogin += "   <div style=\"text-align:center;\">" + newLine;
            str_UserLogin += "       <table><tr><td align=\"center\">欢迎<span style=\"font-weight:bold;\"><font color=\"red\">" + NetCMS.Global.Current.UserName + "</font></span> 再次登录</td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/index.aspx?urls=" + NetCMS.Publish.CommonData.getUrl() + "/" + NetCMS.Config.UIConfig.dirUser + "/info/userinfo.aspx\" target=\"_blank\">资料</a></td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/index.aspx?urls=" + NetCMS.Publish.CommonData.getUrl() + "/" + NetCMS.Config.UIConfig.dirUser + "/photo/Photoalbumlist.aspx\" target=\"_blank\">相册</a></td>";
            str_UserLogin += "       <td align=\"center\"><a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/Index.aspx\" target=\"_blank\">管理</a>";
            str_UserLogin += "       <td align=\"center\"><a href=\"javascript:LoginOut();\">退出</a></td></tr>";
            str_UserLogin += "   </div>" + newLine;
        }
        return str_UserLogin;
    }

    /// <summary>
    /// 退出
    /// </summary>
    protected void UserLoginOut()
    {   
        UserLoginForm();
        Logout(); 
    }

    /// <summary>
    /// 取得用户登录框
    /// </summary>
    protected void UserLoginForm()
    {
        string str_RandNum = Request.QueryString["RandNum"];
        string str_LoginP = Request.QueryString["LoginP"];
        string str_FormCSS = Request.QueryString["FormCSS"];
        string str_LoginCSS = Request.QueryString["LoginCSS"];
        string str_RegCSS = Request.QueryString["RegCSS"];
        string str_PassCSS = Request.QueryString["PassCSS"];
        string str_ShowStyle = Request.QueryString["ShowStyle"];
        string str_ImagePath = Request.QueryString["ImagePath"];
        string str_CancelImage = Request.QueryString["CancelImage"];
        string str_ShowRest = Request.QueryString["ShowRest"];
        string str_ShowPwd = Request.QueryString["ShowPwd"];

        string formCSS = "";
        string formlogin = "";
        string resetlogin = "";
        string imgsrc = "";
        if (str_FormCSS != string.Empty && str_FormCSS != null)
        {
            formCSS = " class=" + str_FormCSS + "";
        }

        if (str_ShowStyle == "true" || str_ShowStyle==string.Empty)
        {
            formlogin = "<input style=\"font-size:12px;\" class=\"" + str_LoginCSS + "\" type=\"button\" name=\"but_LoginSubmit\" value=\"登录\" onclick=\"javascript:LoginSubmit(this.form);\" />";  
            if (str_ShowRest == "true")
            {
                resetlogin = "<input type=\"reset\" class=\"" + str_LoginCSS + "\" style=\"font-size:12px;\" name=\"Loginreset\" value=\"重置\" />";
            }
        }
        else
        {
            formlogin = "<img src=\"" + str_ImagePath + "\"  class=\"" + str_LoginCSS + "\" onclick=\"javascript:LoginSubmit(this.form);\" /> ";
            formlogin = formlogin.Replace("{@dirfile}", NetCMS.Config.UIConfig.dirFile);
            if (str_ShowRest == "true")
            {
                resetlogin = "<img src=\"" + str_CancelImage + "\"  class=\"" + str_LoginCSS + "\" onclick=\"javascript:document.getElementById('UserName').value='';document.getElementById('UserPwd').value='';\"> ";
                resetlogin = resetlogin.Replace("{@dirfile}", NetCMS.Config.UIConfig.dirFile);
            }
        }
        string Regstr = "注册";
        if (str_RegCSS != string.Empty && str_RegCSS != null)
        {
            Regstr = "<span class=" + str_RegCSS + ">" + Regstr + "</span>";
        }
        string Passstr = "";
        if (str_ShowPwd == "true")
        {
            Passstr = "忘记密码";
            if (str_PassCSS != string.Empty && str_PassCSS != null)
            {
                Passstr = "<span class=" + str_PassCSS + ">" + Passstr + "</span>";
            }
        }
        string str_UserLogin = "";
        str_UserLogin += "<form id=\"Form_UserLogin" + str_RandNum + "\" name=\"Form_UserLogin" + str_RandNum + "\" " +
                         "method=\"post\" action=\"\">" + newLine;
        if (str_LoginP == "true")
        {
            str_UserLogin += "       帐号：<input name=\"UserNum\" " + formCSS + " type=\"text\" id=\"userName\" size=\"10\" maxlength=\"20\" style=\"width:95px;\"/>";
            str_UserLogin += "       密码：<input name=\"UserPwd\" " + formCSS + " type=\"password\" id=\"UserPwd\" size=\"10\" style=\"width:95px;\"/>";  
        }
        else if(str_LoginP == "false")
        {
            str_UserLogin += "   <div>" + newLine;
            str_UserLogin += "       帐号：<input name=\"UserNum\" " + formCSS + " type=\"text\" size=\"10\" maxlength=\"20\" id=\"userName\" style=\"width:95px;\"/>";
            str_UserLogin += "   </div>" + newLine;
            str_UserLogin += "   <div>" + newLine;
            str_UserLogin += "       密码：<input name=\"UserPwd\" " + formCSS + " type=\"password\" id=\"UserPwd\" size=\"10\" style=\"width:95px;\"/> ";
            str_UserLogin += "   </div>" + newLine;
        }
        else if (str_LoginP == "Middle")
        {
            str_UserLogin += "       帐号：<input name=\"UserNum\" " + formCSS + " type=\"text\" id=\"userName\" size=\"10\" maxlength=\"20\" style=\"width:95px;\"/>";
            str_UserLogin += "       密码：<input name=\"UserPwd\" " + formCSS + " type=\"password\" id=\"UserPwd\" size=\"10\" style=\"width:95px;\"/>";
            str_UserLogin += "&nbsp;&nbsp;" + formlogin + "   " + resetlogin + "&nbsp;<a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/Register.aspx\">" + Regstr + "</a>";
            str_UserLogin += "&nbsp;<a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/info/getPassword.aspx\">" + Passstr + "</a>";
        }
        if (str_LoginP != "Middle")
        {
            str_UserLogin += "   <div><br><table><tr><td align=\"center\">" + formlogin + "   " + resetlogin + "</td></tr>";
            str_UserLogin += "   <tr><td align=\"center\">" + "<a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/Register.aspx\">" + Regstr + "</a>";
            str_UserLogin += "   <a href=\"/" + NetCMS.Config.UIConfig.dirUser + "/info/getPassword.aspx\">" + Passstr + "</a></td></tr></table></div>";
        }
        str_UserLogin += "</form>" + newLine;

        Response.Write(str_UserLogin);
        Response.End();
    }
}
